package br.com.atomware.sgtp.client.managed.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;


import br.com.atomware.sgtp.client.scaffold.place.ProxyDetailsView;
import br.com.atomware.sgtp.client.managed.request.EmpresaProxy;

/**
 * Details view for Empresa proxys.
 */
public class EmpresaMobileDetailsView extends Composite implements ProxyDetailsView<EmpresaProxy> {
	interface Binder extends UiBinder<HTMLPanel, EmpresaMobileDetailsView> {}

	private static final Binder BINDER = GWT.create(Binder.class);

	private static EmpresaMobileDetailsView instance;

	public static EmpresaMobileDetailsView instance() {
		if (instance == null) {
			instance = new EmpresaMobileDetailsView();
		}
		return instance;
	}

	EmpresaProxy proxy;
	
	@UiField Element id;
	@UiField Element version;
	@UiField Element nome;
	@UiField Element cnpj;
	@UiField Element inscricaoEstadual;	
	@UiField HasClickHandlers delete;

	private Delegate delegate;

	public EmpresaMobileDetailsView() {
		initWidget(BINDER.createAndBindUi(this));
	}

  	public Widget asWidget() {
		return this;
	}
  
	public boolean confirm(String msg) {
		return Window.confirm(msg);
	}

	public EmpresaProxy getValue() {
		return proxy;
	}

	@UiHandler("delete")
	public void onDeleteClicked(ClickEvent e) {
		delegate.deleteClicked();
	}

	public void setDelegate(Delegate delegate) {
		this.delegate = delegate;
	}

	public void setValue(EmpresaProxy proxy) {
		this.proxy = proxy;
		id.setInnerText(proxy.getId() == null ? "" : String.valueOf(proxy.getId()));
		version.setInnerText(proxy.getVersion() == null ? "" : String.valueOf(proxy.getVersion()));
		nome.setInnerText(proxy.getNome() == null ? "" : String.valueOf(proxy.getNome()));
		cnpj.setInnerText(proxy.getCnpj() == null ? "" : String.valueOf(proxy.getCnpj()));
		inscricaoEstadual.setInnerText(proxy.getInscricaoEstadual() == null ? "" : String.valueOf(proxy.getInscricaoEstadual()));
	}
}
